package com.huiquan.onlineTime.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.huiquan.framework.base.EnhancedBaseDao;
import com.huiquan.onlineTime.domain.OnlineTimeDaily;
import com.huiquan.onlineTime.domain.OnlineTimeDailyDto;
import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class OnlineTimeDailyDao extends EnhancedBaseDao<OnlineTimeDaily> {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "ONLINE_TIME_DAILY.";

	public OnlineTimeDailyDao() {
		super(space);
	}

	public void calculateDaily() {
		insert(space + "CALCULATE_DAILY", sqlMapClient);
	}

	/**
	 * 获取之前8天的数据
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<OnlineTimeDailyDto> retrieveListInDays(String startDate,String endDate) {
		//开始时间和结束时间减1天。由于是统计的创建的时间所以需要减一天
		Map<String, Object> param = new HashMap<>();
		param.put("startDate", startDate);
		param.put("endDate", endDate);
		return (List<OnlineTimeDailyDto>)list(space + "RETRIEVE_LIST_IN_DAYS", param, sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> retrieveMonthlyTotal(Map<String, Object> param) {

		return (List<Map<String, Object>>)list(space + "RETRIEVE_MONTHLY_TOTAL", param, sqlMapClient);
	}
}
